﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using System;
using KBEngine;

public class Login : MonoBehaviour {

	// Use this for initialization
	void Start () {
        this.installEvents();
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    public void installEvents()
    {
        KBEngine.Event.registerOut("onLoginSuccessfully", this, "onLoginSuccessfully");
    }

    public void onLoginSuccessfully() {
        SceneManager.LoadScene("Main");
    }

    //字典转为json字符串
    public string dictToJson(Dictionary<string,string> dict) {
        string str = "{";
        foreach(string key in dict.Keys)
        {
            str += ("\"" + key + "\"" + ":" + "\"" + dict[key] + "\"" + ",");
        }
        str = str.Substring(0, str.Length - 1);
        str += "}";
        return str;
    }

    public void onBtnLoginClick() {
        Dictionary<string, string> datas = new Dictionary<string, string>();
        datas.Add("platform", "h5_temp");
        datas.Add("nickName", "hehe");
        string strDatas = this.dictToJson(datas);
        KBEngine.Event.fireIn("login", "utest12230002", "123456", System.Text.Encoding.UTF8.GetBytes(strDatas));
    }
}
